﻿# -*- coding: utf-8 -*-
"""
请实现一个 python 类，具有上下文管理功能
"""
class Python:
    def __init__(self, x=100):
        self.x = x

    def __enter__(self):
        print('----打开前------')
        return self.x

    def __exit__(self, exc_type, exc_val, exc_tb):
        print('----关闭后------')


def main():
    print('-' * 30)
    with Python() as f:
        print('=' * 30)
        print(f)


if __name__ == '__main__':
    main()
# 写出来了，说明基础学的不错，知道是实现了enter和exit方法